import java.util.Arrays;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 邓大帅
 * Date: 2022-12-17
 * Time: 15:07
 */
public class BubbleSort {
    public static void bubbleSort(int[] array) {
        int j = array.length;
        while (j != 0) {
            for (int i = 0; i < j-1; i++) {
                if (array[i] > array[i+1]) {
                    int temp = array[i];
                    array[i] = array[i+1];
                    array[i+1] = temp;
                }
            }
            j--;
        }
    }
    public static void main(String[] args) {
        int[] array = new int[]{2,8,1,7,9,6,4,3,5};
        bubbleSort(array);
        System.out.println(Arrays.toString(array));
    }
}
